package com.ljw.log;

import com.ljw.Utils.HbaseUtil;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.RegexStringComparator;
import org.apache.hadoop.hbase.filter.RowFilter;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * Created by admin on 2017/11/5.
 */
public class SelectHbase {
    public Admin admin= HbaseUtil.getAdmin();
    public Table table=null;
    Connection connection=HbaseUtil.getConnection();
    /**
     * 查询14563789098手机号的所有数据
     */
   public void getAllByRowKey() throws Exception{
       String tableName="";
       String startRow="14563789098_/";
       String stopRow="14563789098_:";

       table=connection.getTable(TableName.valueOf(tableName));
       Scan scan=new Scan();
//       ==========================
       scan.setStartRow(Bytes.toBytes(startRow));
       scan.setStopRow(Bytes.toBytes(stopRow));
//       ================================
//       String reg="14563789098_*";
//       Filter filter=new RowFilter(CompareFilter.CompareOp.EQUAL,new RegexStringComparator(reg));
//        scan.setFilter(filter);
       ResultScanner resultScanner = table.getScanner(scan);
       for (Result result:resultScanner) {
           for (Cell cell:result.rawCells()) {
               System.out.println("表的主键名：" + Bytes.toString(result.getRow()));
               System.out.println("表的单元格的列组名：" + CellUtil.cloneFamily(cell));
               System.out.println("单元格的列名：" + CellUtil.cloneQualifier(cell));
               System.out.println("单元格的值：" + CellUtil.cloneValue(cell));
           }
       }

   }
}
